import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { HttpProvider } from '../../providers/http/http';
import { StorageProvider } from '../../providers/storage/storage';
import { DialogProvider } from '../../providers/dialog/dialog';
/**
 * Generated class for the Resourcesinput page.
 *
 * See http://ionicframework.com/docs/components/#navigation for more info
 * on Ionic pages and navigation.
 */
@IonicPage()
@Component({
	selector: 'page-resourcesinput',
	templateUrl: 'resourcesinput.html',
})
export class ResourcesinputPage {
	/**
	 * 输入界面控制
	 */
	inputSelectView = {
		applysexDefItems: new Array(), //性别数组
		applyoaminDate: '',
		applyoamaxDate: '',
		applylevelDefItems: new Array(), //岗级数组
	}
	/**
	 * 输入界面控制
	 */
	inputView = {
		applyapplywroker: false, //员工姓名
		applyapplywrokerlogin: false, //登录者
		applyapplywrokerdepart: false, //所属公司部门
		applyapplywrokerpalce: false, //当前岗位 当前岗级
		applyapplywrokerpalcechange: false, //变更岗位
		applyapplywrokerpalcelevel: false, //调整后岗级
		applyjoinworkjointime: false, //入职时间
		applyjoinworkleavetime: false, //离职时间
		applyapplywrokerdepartmanager: false, //部门主管

		applyapplyname: false, //姓名
		applyapplysex: false, //性别
		applyapplyplace: false, //籍贯
		applybirthday: false, //出生年月
		applynation: false, //民族
		applybirthaddress: false, //出生地
		applycardno: false, //身份证号码
		applyplaceaddress: false, //户籍所在地
		applyaffiliation: false, //政治面貌
		applyhealthstatus: false, //健康状况
		applyheight: false, //身高
		applyweight: false, //体重
		applyjointuantime: false, //入团时间
		applyjoinpartytime: false, //入党时间
		applymarriagestatus: false, //婚姻状况
		applyworktime: false, //参加工作时间
		applyurgentname: false, //紧急联系人
		applyurgentmobile: false, //紧急联系人号码
		applycomputerlevel: false, //计算机水平
		applylanguagelevel: false, //外语水平
		applymobile: false, //联系电话

		applynextnode: false, //下一步处理环节
		applynextman: false, //下一步处理人
	}
	/**
	 * 输入界面控制
	 */
	inputViewName = {
		applyapplywroker: '员工姓名', //员工姓名
		applyapplywrokerlogin: '登录者', //登录者
		applyapplywrokerdepart: '所属公司部门', //所属公司部门
		applyapplywrokerpalce: '当前岗位', //当前岗位
		applyapplywrokerpalcechange: '变更岗位', //变更岗位
		applyapplywrokerpalcelevel: '调整后岗级', //调整后岗级
		applyjoinworkjointime: '入职时间', //入职时间
		applyjoinworkleavetime: '离职时间', //离职时间
		applyapplywrokerdepartmanager: '部门主管', //部门主管

		applyapplyname: '姓名', //姓名
		applyapplysex: '性别', //性别
		applyapplyplace: '籍贯', //籍贯
		applybirthday: '出生年月', //出生年月
		applynation: '民族', //出生年月
		applybirthaddress: '出生地', //出生地
		applycardno: '身份证号码', //身份证号码
		applyplaceaddress: '户籍所在地', //户籍所在地
		applyaffiliation: '政治面貌', //政治面貌
		applyhealthstatus: '健康状况', //健康状况
		applyheight: '身高', //身高
		applyweight: '体重', //体重
		applyjointuantime: '入团时间', //入团时间
		applyjoinpartytime: '入党时间', //入党时间
		applymarriagestatus: '婚姻状况', //婚姻状况
		applyworktime: '参加工作时间', //参加工作时间
		applyurgentname: '紧急联系人', //紧急联系人
		applyurgentmobile: '紧急联系人号码', //紧急联系人号码
		applycomputerlevel: '计算机水平', //计算机水平
		applylanguagelevel: '外语水平', //外语水平
		applymobile: '联系电话', //联系电话

		applynextnode: '下一步处理环节', //下一步处理环节
		applynextman: '下一步处理人', //下一步处理人
	}
	/**
	 * 输入界面控制
	 */
	inputViewModel = {
		applyapplywroker: '', //员工姓名
		applyapplywrokerlogin: '', //登录者
		applyapplywrokerdepart: '', //所属公司部门
		applyapplywrokerpalce: '', //当前岗位
		applyapplywrokerpalcechange: '', //变更岗位
		applyapplywrokerpalcelevel: '', //调整后岗级
		applyjoinworkjointime: '', //入职时间
		applyjoinworkleavetime: '', //离职时间
		applyapplywrokerdepartmanager: '', //部门主管

		applyapplyname: '', //姓名
		applyapplysex: '', //性别
		applyapplyplace: '', //籍贯
		applybirthday: '', //出生年月
		applynation: '', //出生年月
		applybirthaddress: '', //出生地
		applycardno: '', //身份证号码
		applyplaceaddress: '', //户籍所在地
		applyaffiliation: '', //政治面貌
		applyhealthstatus: '', //健康状况
		applyheight: '', //身高
		applyweight: '', //体重
		applyjointuantime: '', //入团时间
		applyjoinpartytime: '', //入党时间
		applymarriagestatus: '', //婚姻状况
		applyworktime: '', //参加工作时间
		applyurgentname: '', //紧急联系人
		applyurgentmobile: '', //紧急联系人号码
		applycomputerlevel: '', //计算机水平
		applylanguagelevel: '', //外语水平
		applymobile: '', //联系电话

		applynextnode: '', //下一步处理环节
		applynextman: '', //下一步处理人
	}
	/**
	 * 页面类型
	 */
	private type: Number;
	/**
	 * 标题
	 */
	private title: String;

	constructor(
		public navCtrl: NavController,
		public navParams: NavParams,
		public http: HttpProvider,
		public storage: StorageProvider,
		public dialog: DialogProvider) {
		this.type = this.navParams.get("type"); //页面类型
		this.inputSelectView.applyoaminDate = '2000-01-01';
		this.inputSelectView.applyoamaxDate = this.getinitDate();
	}

	ionViewDidLoad() {
		console.log('ionViewDidLoad Resourcesinput');
		//控制显示
		this.ionViewDidShow();
	}
	ionViewDidShow() {
		//1.入职填报
		if(this.type == 1) {
			this.title = '入职填报';
			this.inputView.applyapplyname = true;
			this.inputView.applyapplysex = true;
			this.inputView.applyapplyplace = true;
			this.inputView.applybirthday = true;
			this.inputView.applynation = true;
			this.inputView.applybirthaddress = true;
			this.inputView.applycardno = true;
			this.inputView.applyplaceaddress = true;
			this.inputView.applyaffiliation = true;
			this.inputView.applyhealthstatus = true;
			this.inputView.applyheight = true;
			this.inputView.applyweight = true;
			this.inputView.applyjointuantime = true;
			this.inputView.applyjoinpartytime = true;
			this.inputView.applymarriagestatus = true;
			this.inputView.applyworktime = true;
			this.inputView.applyurgentname = true;
			this.inputView.applyurgentmobile = true;
			this.inputView.applycomputerlevel = true;
			this.inputView.applylanguagelevel = true;
			this.inputView.applymobile = true;
			this.loadsexDefData();
		}
		//2.岗位变更
		if(this.type == 2) {
			this.title = '岗位变更';
			this.inputView.applyapplywroker = true;
			this.inputView.applyapplywrokerlogin = true;
			this.inputView.applyapplywrokerpalce = true;
			this.inputView.applyapplywrokerpalcechange = true;
			this.inputViewModel.applynextnode = '用人部门审核';
			this.inputView.applynextnode = true;
			this.inputView.applynextman = true;
		}
		//3.岗级变更
		if(this.type == 3) {
			this.title = '岗级变更';
			this.inputView.applyapplywroker = true;
			this.inputView.applyapplywrokerlogin = true;
			this.inputView.applyapplywrokerdepart = true;
			this.inputView.applyapplywrokerpalce = true;
			this.inputViewName.applyapplywrokerpalce = '当前岗级';
			this.inputView.applyapplywrokerpalcelevel = true;
			this.inputViewModel.applynextnode = '用人部门审核';
			this.inputView.applynextnode = true;
			this.inputView.applynextman = true;
			this.loadlevelDefData();
		}
		//4.离职审批
		if(this.type == 4) {
			this.title = '离职审批';
			this.inputView.applyapplywroker = true;
			this.inputView.applyapplywrokerdepart = true;
			this.inputViewName.applyapplywrokerdepart = '公司职务';
			this.inputView.applyjoinworkjointime = true;
			this.inputView.applyjoinworkleavetime = true;
			this.inputView.applyapplywrokerdepartmanager = true;
			this.inputViewModel.applynextnode = '用人部门审核';
			this.inputView.applynextnode = true;
			this.inputView.applynextman = true;
		}
		//5.员工审核申请
		if(this.type == 5) {
			this.title = '员工审核申请';
			this.inputView.applyapplyname = true;
			this.inputView.applyapplysex = true;
			this.inputView.applyapplyplace = true;
			this.inputView.applybirthday = true;
			this.inputView.applynation = true;
			this.inputView.applybirthaddress = true;
			this.inputView.applycardno = true;
			this.inputView.applyplaceaddress = true;
			this.inputView.applyaffiliation = true;
			this.inputView.applyhealthstatus = true;
			this.inputView.applyheight = true;
			this.inputView.applyweight = true;
			this.inputView.applyjointuantime = true;
			this.inputView.applyjoinpartytime = true;
			this.inputView.applymarriagestatus = true;
			this.inputView.applyworktime = true;
			this.inputView.applyurgentname = true;
			this.inputView.applyurgentmobile = true;
			this.inputView.applycomputerlevel = true;
			this.inputView.applylanguagelevel = true;
			this.inputView.applymobile = true;
		}
		//6.劳动合同续签
		if(this.type == 6) {
			this.title = '劳动合同续签';
			this.inputView.applyapplyname = true;
			this.inputView.applyapplysex = true;
			this.inputView.applyapplyplace = true;
			this.inputView.applybirthday = true;
			this.inputView.applynation = true;
			this.inputView.applybirthaddress = true;
			this.inputView.applycardno = true;
			this.inputView.applyplaceaddress = true;
			this.inputView.applyaffiliation = true;
			this.inputView.applyhealthstatus = true;
			this.inputView.applyheight = true;
			this.inputView.applyweight = true;
			this.inputView.applyjointuantime = true;
			this.inputView.applyjoinpartytime = true;
			this.inputView.applymarriagestatus = true;
			this.inputView.applyworktime = true;
			this.inputView.applyurgentname = true;
			this.inputView.applyurgentmobile = true;
			this.inputView.applycomputerlevel = true;
			this.inputView.applylanguagelevel = true;
			this.inputView.applymobile = true;
		}
	}

	//格式化时间
	getCurrentDate(time: any) {
		// 格式化日期，获取今天的日期
		let Dates = new Date(time);
		let year = Dates.getFullYear();
		let month = (Dates.getMonth() + 1) < 10 ? '0' + (Dates.getMonth() + 1) : (Dates.getMonth() + 1);
		let day = Dates.getDate() < 10 ? '0' + Dates.getDate() : Dates.getDate();
		let hours = Dates.getHours() < 10 ? '0' + Dates.getHours() : Dates.getHours();
		let minutes = Dates.getMinutes() < 10 ? '0' + Dates.getMinutes() : Dates.getMinutes();
		let seconds = Dates.getSeconds() < 10 ? '0' + Dates.getSeconds() : Dates.getSeconds();
		return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
	};

	//格式化时间
	getinitDate() {
		// 格式化日期，获取今天的日期
		let Dates = new Date(new Date().getTime());
		let year = Dates.getFullYear() + 1;
		let month = (Dates.getMonth() + 1) < 10 ? '0' + (Dates.getMonth() + 1) : (Dates.getMonth() + 1);
		let day = Dates.getDate() < 10 ? '0' + Dates.getDate() : Dates.getDate();

		return year + '-' + month + '-' + day;
	};

	//初始化性别
	loadsexDefData() {
		//初始化
		let params = new Object();
		params['type'] = 'sex';
		this.http.postJson('dict', 'getDictByType.do', params).then(res => {
			let datas = res['data']['dictList'];
			this.inputSelectView.applysexDefItems = new Array();
			for(let i = 0; i < datas.length; i++) {
				let item = datas[i];
				this.inputSelectView.applysexDefItems.push({
					id: item['id'],
					name: item['value']
				});
			}
		});
	}

	//岗级初始化
	loadlevelDefData() {
		//初始化
		let params = new Object();
		params['type'] = 'user_post_grade';
		this.http.postJson('dict', 'getDictByType.do', params).then(res => {
			let datas = res['data']['dictList'];
			this.inputSelectView.applylevelDefItems = new Array();
			for(let i = 0; i < datas.length; i++) {
				let item = datas[i];
				this.inputSelectView.applylevelDefItems.push({
					id: item['id'],
					name: item['value']
				});
			}
		});
	}

	//初始化选择用户
	applyapplymemberselect(type) {
		//共通弹出
		let data = new Object();
		if(type == 1)
			data['selectitem'] = this.inputViewModel.applynextman;
		if(type == 2)
			data['selectitem'] = this.inputViewModel.applyapplywroker;
		if(type == 3)
			data['selectitem'] = this.inputViewModel.applyapplywrokerdepartmanager;
		if(type == 4)
			data['selectitem'] = this.inputViewModel.applyapplywrokerpalcechange;

		data['multiselect'] = false; //false 单选 true 多选
		let opts = new Object();
		this.dialog.showModal("ModaluserselectPage", data, opts).then(success => {
			//界面关闭的时候
			if(success) {
				let result = success['result'];
				if(type == 1)
					this.inputViewModel.applynextman = result[0];
				if(type == 2)
					this.inputViewModel.applyapplywroker = result[0];
				if(type == 3)
					this.inputViewModel.applyapplywrokerdepartmanager = result[0];
				if(type == 4)
					this.inputViewModel.applyapplywrokerpalcechange = result[0];
			}
		});
	}

	//变更类型对比选中
	compareselect(e1: Object, e2: Object) {
		return e1 && e2 ? e1['id'] === e2['id'] : e1 === e2;
	}
}